<!DOCTYPE html>
 <html>
     <head>
         <meta charset="utf-8">
         <title>计算器</title>
     </head>
     <body>
         <form class="" action="" method="post">
             <input type="text" name="num1">
             <select class="" name="method">
                 <option value="add">+</option>
                 <option value="sub">-</option>
                 <option value="multi">*</option>
                 <option value="div">/</option>
             </select>
             <input type="text" name="num2">
             <input type="submit" name="submit" value="Submit">
         </form>

         <?php
         if(isset($_POST['submit'])){

             $float = true;

             if($_POST['num1']==null || $_POST['num2']==null || !is_numeric($_POST['num1']) || !is_numeric($_POST['num2']) ) {
                 $float=false;
                 echo "请输入数字！";
             }
             if($float){
                 switch ($_POST['method']) {
                     case 'add':
                         $result=$_POST['num1']+$_POST['num2'];
                         echo $result;
                         break;
                     case 'sub':
                         $result=$_POST['num1']-$_POST['num2'];
                         echo $result;
                         break;
                     case 'multi':
                         $result=$_POST['num1']*$_POST['num2'];
                         echo $result;
                         break;
                     case 'div':
                         $result=$_POST['num1']/$_POST['num2'];
                         echo $result;
                         break;
                     default:
                         echo "You have to choise a method.";
                         break;
                 }
             }
         }
          ?>
     </body>
 </html>
